package com.zxbg.dao;

import com.zxbg.domain.App;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AppDao {
    @Select("select * from app where category_id = #{category_id} and tenant_id = #{tenant_id} order by `order`")
    public List<App> getAppByCategoryId(@Param("category_id") Integer category_id, @Param("tenant_id") Integer tenant_id);

    @Select("select * from app where category_id = #{category_id} and app_name like #{key} and tenant_id = #{tenant_id} order by `order`")
    public List<App> getAppByCategoryIdAndName(@Param("category_id") Integer category_id, @Param("key") String key, @Param("tenant_id") Integer tenant_id);

    @Update("update app set `order` = #{order}, update_time = NOW() where app_id = #{app_id} and tenant_id = #{tenant_id}")
    public int changeAppOrder(@Param("app_id") String app_id, @Param("order") Integer order, @Param("tenant_id") Integer tenant_id);

    @Select("select * from app where app_id = #{app_id} and tenant_id = #{tenant_id}")
    public App getAppByAppId(@Param("app_id") String app_id, @Param("tenant_id") Integer tenant_id);

    @Select("select * from app where tenant_id = #{tenant_id}")
    public List<App> getAllApps(Integer tenant_id);

    @Update("update app set app_name = #{app_name}, category_id = #{category_id}, icon_index = #{icon_index}, update_time = NOW(), `describe` = #{describe} where app_id = #{app_id} and tenant_id = #{tenant_id}")
    public int updateApp(App app);
}
